package com.hemaapp.yjnh.activity;

import xtom.frame.util.XtomToastUtil;
import android.content.Intent;
import android.os.Bundle;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

import com.hemaapp.hm_FrameWork.HemaNetTask;
import com.hemaapp.hm_FrameWork.result.HemaBaseResult;
import com.hemaapp.yjnh.BaseActivity;
import com.hemaapp.yjnh.BaseHttpInformation;
import com.hemaapp.yjnh.BaseUtil;
import com.hemaapp.yjnh.R;

/**
 * 注册第二步
 */
public class Register1Activity extends BaseActivity {
	private TextView titleText;
	private ImageButton titleLeft;
//	private Button titleRight;

	private EditText passwordEditText;
	private EditText repeatEditText;
	private Button nextButton;

	private String tempToken;
	private String username;
	private String password;
	private String invitation;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.activity_register1);
		super.onCreate(savedInstanceState);
	}

	@Override
	protected void callBeforeDataBack(HemaNetTask netTask) {

	}

	@Override
	protected void callAfterDataBack(HemaNetTask netTask) {
		// TODO Auto-generated method stub

	}

	@Override
	protected void callBackForServerSuccess(HemaNetTask netTask,
			HemaBaseResult baseResult) {
		BaseHttpInformation information = (BaseHttpInformation) netTask
				.getHttpInformation();
		switch (information) {
		case INIT:
			break;
		case CLIENT_LOGIN:
			break;
		default:
			break;
		}

	}

	@Override
	protected void callBackForServerFailed(HemaNetTask netTask,
			HemaBaseResult baseResult) {
		BaseHttpInformation information = (BaseHttpInformation) netTask
				.getHttpInformation();
		switch (information) {
		case INIT:
			// getInitFailed();
			break;
		case CLIENT_LOGIN:
			// toLogin();
			break;
		default:
			break;
		}
	}

	@Override
	protected void callBackForGetDataFailed(HemaNetTask netTask, int failedType) {
		BaseHttpInformation information = (BaseHttpInformation) netTask
				.getHttpInformation();
		switch (information) {
		case INIT:
			// getInitFailed();
			break;
		case CLIENT_LOGIN:
			// toLogin();
			break;
		default:
			break;
		}
	}

	@Override
	protected void findView() {
		titleText = (TextView) findViewById(R.id.title_text);
		titleLeft = (ImageButton) findViewById(R.id.title_left_btn);

		passwordEditText = (EditText) findViewById(R.id.password);
		repeatEditText = (EditText) findViewById(R.id.repeat);
		nextButton = (Button) findViewById(R.id.next);
	}

	@Override
	protected void getExras() {
		username = mIntent.getStringExtra("username");
		tempToken = mIntent.getStringExtra("tempToken");
		invitation = getIntent().getStringExtra("invitation");
		log_i("tempToken = " + tempToken);
		log_i("username = " + username);
		log_i("invitation = " + invitation);
	}

	@Override
	protected void setListener() {
		titleText.setText("设置密码");
		titleLeft.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}
		});
		nextButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				password = passwordEditText.getText().toString().trim();
				String repeat = repeatEditText.getText().toString().trim();
				if (password.length()<6 || password.length()>16) {
					XtomToastUtil.showShortToast(mContext, "密码输入不正确，请输入6-16位密码");
					return;
				}
				if (!password.equals(repeat)) {
					XtomToastUtil.showShortToast(mContext, "密码输入不一致，请重新输入!");
					return;
				}
				Intent it = new Intent(mContext, Register2Activity.class);
				it.putExtra("username", username);
				it.putExtra("password", password);
				it.putExtra("tempToken", tempToken);
				it.putExtra("invitation", invitation);
				it.putExtra("type", 1);
				startActivity(it);
			}
		});
		passwordEditText.setHint("密码");
		repeatEditText.setHint("确认新密码");
	}
}
